package com.itboye.jmsfhz.app.adapter;

import java.text.SimpleDateFormat;

import com.itboye.config.GlobalConfig;
import com.itboye.core.utils.XImageLoader;
import com.itboye.jmsfhz.R;
import com.lfh.commentdemo.bean.AppModelNewsBean;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class GongGaoAdapter extends BaseAdapter {
	Context context;
	AppModelNewsBean bean;

	public GongGaoAdapter(Context context,AppModelNewsBean bean) {
		this.context = context;
		this.bean=bean;

	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return bean.getList()==null?0:bean.getList().size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}


	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		// TODO Auto-generated method stub
		ViewHouder houder;
		if (arg1==null) {
//			arg1 = LayoutInflater.from(context).inflate(
//					R.layout.item_gongao_time, null);
			houder=new ViewHouder();
			arg1 = LayoutInflater.from(context).inflate(
					R.layout.item_gongao_one, null);
			houder.time=(TextView) arg1.findViewById(R.id.gonggaoTime);
			houder.title=(TextView) arg1.findViewById(R.id.tvTitleGongGao);
			houder.img=(ImageView) arg1.findViewById(R.id.imgGongGao);
			arg1.setTag(houder);
		}else{
			houder=(ViewHouder) arg1.getTag();
		}
		
		houder.title.setText(bean.getList().get(arg0).getPost_title());
		
		houder.time.setText(new SimpleDateFormat("yyyy-MM-dd").format(Long
				.parseLong(bean.getList().get(arg0).getPost_modified())*1000));
		XImageLoader.load(GlobalConfig.JIUYE+bean.getList().get(arg0).getMain_img(), houder.img);
		return arg1;
	}
	class  ViewHouder{
		private TextView time;
		private TextView title;
		private ImageView img;
	}
}
